package service

import (
	"context"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 添加站内信信息
func (s *Server) InAppInfoAdd(_ context.Context, in *__.InAppInfoAddReq) (*__.InAppInfoAddResp, error) {

	id, err := dao.CreateAppInfo(in)
	if err != nil {
		return nil, err
	}
	return &__.InAppInfoAddResp{
		Id: int64(id),
	}, nil
}

// 站内信列表
func (s *Server) InAppInfoList(_ context.Context, in *__.InAppInfoListReq) (*__.InAppInfoListResp, error) {
	list, err := dao.InAppInfoList(in)
	if err != nil {
		return nil, err
	}
	return &__.InAppInfoListResp{List: list}, nil
}

// 站内信详情
func (s *Server) InAppInfoDetail(_ context.Context, in *__.InAppInfoDetailReq) (*__.InAppInfoDetailResp, error) {
	i, err := dao.InAppInfoDetail(in)
	if err != nil {
		return nil, err
	}
	return &__.InAppInfoDetailResp{
		Id:       int64(i.Id),
		ToUserId: i.ToUserId,
		Title:    i.Title,
		Content:  i.Content,
		Types:    int64(i.Types),
		IsRead:   uint32(i.IsRead),
	}, nil
}

// 修改站内信信息已读状态
func (s *Server) UpdateInAppInfoUsRead(_ context.Context, in *__.UpdateInAppInfoUsReadReq) (*__.UpdateInAppInfoUsReadResp, error) {
	err := dao.UpdateIsRead(in.Id)
	if err != nil {
		return nil, err
	}
	return &__.UpdateInAppInfoUsReadResp{
		Id: in.Id,
	}, nil
}
